package com.example.park

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.example.lib_base.entity.CarTypeEntityItem
import com.example.park.databinding.ItemCartypeBinding


class ParkAdapter:PagingDataAdapter<CarTypeEntityItem, ParkAdapter.ParkViewHolder>(diff) {

    companion object{
        val diff = object:ItemCallback<CarTypeEntityItem>() {
            override fun areItemsTheSame(
                oldItem: CarTypeEntityItem,
                newItem: CarTypeEntityItem
            ): Boolean {
                return oldItem == newItem
            }

            override fun areContentsTheSame(
                oldItem: CarTypeEntityItem,
                newItem: CarTypeEntityItem
            ): Boolean {
                return oldItem.id == newItem.id
            }

        }
    }
    class ParkViewHolder(view:View):ViewHolder(view){
        val binding=DataBindingUtil.bind<ItemCartypeBinding>(view)
    }

    override fun onBindViewHolder(holder: ParkViewHolder, position: Int) {
        holder.binding?.car = getItem(position)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ParkViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_cartype, parent, false)
        return ParkViewHolder(view)
    }
}